package fina2.dcs.context;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import fina2.dcs.fis.BankBranchLocal;
import fina2.dcs.fis.BankGroupLocal;
import fina2.dcs.fis.BankLocal;
import fina2.dcs.fis.BankManagementLocal;
import fina2.dcs.fis.BankTypeLocal;
import fina2.dcs.fis.CriterionLocal;
import fina2.dcs.fis.LicenceLocal;
import fina2.dcs.fis.LicenceTypeLocal;
import fina2.dcs.fis.MMBankGroupLocal;
import fina2.dcs.fis.ManagingBodyLocal;
import fina2.dcs.fis.RegionLocal;
import fina2.dcs.i18n.LanguageLocal;
import fina2.dcs.returns.ReturnTypeLocal;
import fina2.dcs.returns.ReturnVersionLocal;
import fina2.dcs.security.PermissionLocal;
import fina2.dcs.security.RoleLocal;
import fina2.dcs.security.UserLocal;
import fina2.dcs.security.UserPermissionLocal;
import fina2.dcs.system.SysPropertyLocal;
import fina2.dcs.system.SysStringLocal;
import fina2.dcs.system.SysUserBankLocal;
import fina2.dcs.upload.UploadedFileLocal;

public class ContextHelper {

	private static InitialContext initContext = null;

	private static SysStringLocal sysStringLocal = null;

	private static BankLocal bankLocal = null;

	private static BankBranchLocal bankBranchLocal = null;

	private static MMBankGroupLocal mmBGroupLocal = null;

	private static BankGroupLocal bankGroupLocal = null;

	private static BankTypeLocal bankTypeLocal = null;

	private static CriterionLocal critLocal = null;

	private static LicenceLocal licLocal = null;

	private static LicenceTypeLocal licTypeLocal = null;

	private static UserLocal userLocal = null;

	private static ReturnTypeLocal retTypeLocal = null;

	private static ReturnVersionLocal retVersionLocal = null;

	private static SysPropertyLocal sysPropLocal = null;

	private static SysUserBankLocal sysUserBankLocal = null;

	private static LanguageLocal langLocal = null;

	private static UploadedFileLocal uploadedFileLocal = null;

	private static UserPermissionLocal userPermissionLocal = null;

	private static PermissionLocal permLocal = null;

	private static RegionLocal regionLocal = null;

	private static ManagingBodyLocal managingBodyLocal = null;

	private static BankManagementLocal bankManagementLocal = null;

	private static RoleLocal roleLocal = null;

	private ContextHelper() {

	}

	public static void clearAll() {
		initContext = null;
		userLocal = null;
	}

	public static InitialContext getInitialContext() throws NamingException {
			initContext = new InitialContext();
		return initContext;
	}

	public static SysStringLocal injectSysStringLocal(InitialContext ic) throws NamingException {
	//	if (sysStringLocal == null)
			sysStringLocal = (SysStringLocal) ic.lookup("SysStringSession/local");
		return sysStringLocal;
	}

	public static BankLocal injectBankLocal(InitialContext ic) throws NamingException {
		//if (bankLocal == null)
			bankLocal = (BankLocal) ic.lookup("BankSession/local");
		return bankLocal;
	}

	public static BankBranchLocal injectBankBranchLocal(InitialContext ic) throws NamingException {
		//if (bankBranchLocal == null)
			bankBranchLocal = (BankBranchLocal) ic.lookup("BankBranchSession/local");
		return bankBranchLocal;
	}

	public static MMBankGroupLocal injectMMBankGroupLocal(InitialContext ic) throws NamingException {
		//if (mmBGroupLocal == null)
			mmBGroupLocal = (MMBankGroupLocal) ic.lookup("MMBankGroupSession/local");
		return mmBGroupLocal;
	}

	public static BankGroupLocal injectBankGroupLocal(InitialContext ic) throws NamingException {
		//if (bankGroupLocal == null)
			bankGroupLocal = (BankGroupLocal) ic.lookup("BankGroupSession/local");
		return bankGroupLocal;
	}

	public static BankTypeLocal injectBankTypeLocal(InitialContext ic) throws NamingException {
		//if (bankTypeLocal == null)
			bankTypeLocal = (BankTypeLocal) ic.lookup("BankTypeSession/local");
		return bankTypeLocal;
	}

	public static CriterionLocal injectCriterionLocal(InitialContext ic) throws NamingException {
		//if (critLocal == null)
			critLocal = (CriterionLocal) ic.lookup("CriterionSession/local");
		return critLocal;
	}

	public static LicenceLocal injectLicenceLocal(InitialContext ic) throws NamingException {
		//if (licLocal == null)
			licLocal = (LicenceLocal) ic.lookup("LicenceSession/local");
		return licLocal;
	}

	public static LicenceTypeLocal injectLicenceTypeLocal(InitialContext ic) throws NamingException {
		//if (licTypeLocal == null)
			licTypeLocal = (LicenceTypeLocal) ic.lookup("LicenceTypeSession/local");
		return licTypeLocal;
	}

	public static UserLocal injectUserLocal(InitialContext ic) throws NamingException {
		//if (userLocal == null)
			userLocal = (UserLocal) ic.lookup("UserSession/local");
		return userLocal;
	}

	public static SysPropertyLocal injectSysPropLocal(InitialContext ic) throws NamingException {
		//if (sysPropLocal == null)
			sysPropLocal = (SysPropertyLocal) ic.lookup("SysPropertySession/local");
		return sysPropLocal;
	}

	public static SysUserBankLocal injectSysUserBankLocal(InitialContext ic) throws NamingException {
		//if (sysUserBankLocal == null)
			sysUserBankLocal = (SysUserBankLocal) ic.lookup("SysUserBankSession/local");
		return sysUserBankLocal;
	}

	public static ReturnTypeLocal injectRetTypeLocal(InitialContext ic) throws NamingException {
		//if (retTypeLocal == null)
			retTypeLocal = (ReturnTypeLocal) ic.lookup("ReturnTypeSession/local");
		return retTypeLocal;
	}

	public static ReturnVersionLocal injectRetVersionLocal(InitialContext ic) throws NamingException {
		//if (retVersionLocal == null)
			retVersionLocal = (ReturnVersionLocal) ic.lookup("ReturnVersionSession/local");
		return retVersionLocal;
	}

	public static LanguageLocal injectLangLocal(InitialContext ic) throws NamingException {
		//if (langLocal == null)
			langLocal = (LanguageLocal) ic.lookup("LanguageSession/local");
		return langLocal;
	}

	public static UploadedFileLocal injectUploadedFileLocal(InitialContext ic) throws NamingException {
		//if (uploadedFileLocal == null)
			uploadedFileLocal = (UploadedFileLocal) ic.lookup("UploadedFileSession/local");
		return uploadedFileLocal;
	}

	public static RegionLocal injectRegionLocal(InitialContext ic) throws NamingException {
		//if (regionLocal == null)
			regionLocal = (RegionLocal) ic.lookup("RegionSession/local");
		return regionLocal;
	}

	public static BankManagementLocal injectBankManagementLocal(InitialContext ic) throws NamingException {
		//if (bankManagementLocal == null)
			bankManagementLocal = (BankManagementLocal) ic.lookup("BankManagementSession/local");
		return bankManagementLocal;
	}

	public static ManagingBodyLocal injectManagingBodyLocal(InitialContext ic) throws NamingException {
		//if (managingBodyLocal == null)
			managingBodyLocal = (ManagingBodyLocal) ic.lookup("ManagingBodySession/local");
		return managingBodyLocal;
	}

	public static UserPermissionLocal injectUserPermissionLocal(InitialContext ic) throws NamingException {
		//if (userPermissionLocal == null)
			userPermissionLocal = (UserPermissionLocal) ic.lookup("UserPermissionSession/local");
		return userPermissionLocal;
	}

	public static PermissionLocal injectPermissionLocal(InitialContext ic) throws NamingException {
		//if (permLocal == null)
			permLocal = (PermissionLocal) ic.lookup("PermissionSession/local");
		return permLocal;
	}

	public static RoleLocal injectRoleLocal(InitialContext ic) throws NamingException {
		//if (roleLocal == null)
			roleLocal = (RoleLocal) ic.lookup("RoleSession/local");
		return roleLocal;
	}

	public static void injectAll() throws NamingException {
		getInitialContext();
		injectManagingBodyLocal(initContext);
		injectBankGroupLocal(initContext);
		injectBankLocal(initContext);
		injectBankBranchLocal(initContext);
		injectBankTypeLocal(initContext);
		injectBankManagementLocal(initContext);
		injectCriterionLocal(initContext);
		injectPermissionLocal(initContext);
		injectLicenceLocal(initContext);
		injectLicenceTypeLocal(initContext);
		injectMMBankGroupLocal(initContext);
		injectSysPropLocal(initContext);
		injectSysStringLocal(initContext);
		injectSysUserBankLocal(initContext);
		injectUserLocal(initContext);
		injectUserPermissionLocal(initContext);
		injectRetTypeLocal(initContext);
		injectRetVersionLocal(initContext);
		injectLangLocal(initContext);
		injectUploadedFileLocal(initContext);
		injectRegionLocal(initContext);
		injectRoleLocal(initContext);
	}
}
